<template>
  <main id="main">
    <router-view></router-view>
  </main>
</template>

<script setup lang="ts">
import { Boot } from '@wangeditor/editor'
import attachmentModule from '@wangeditor/plugin-upload-attachment'
// 注册。要在创建编辑器之前注册，且只能注册一次，不可重复注册。
Boot.registerModule(attachmentModule)

import { ElMessage, ElMessageBox } from "element-plus";

import { useStore } from "vuex";

const store = useStore();

if (sessionStorage.getItem("store")) {
  store.replaceState(
    Object.assign({}, store.state, JSON.parse(sessionStorage.getItem("store")))
  );
}

//在页面刷新时将vuex里的信息保存到sessionStorage里
window.addEventListener("beforeunload", () => {
  sessionStorage.setItem("store", JSON.stringify(store.state));
});

window.alert = function (value: string | any): void {
  if (typeof value == "object") {
    ElMessage(value);
  } else {
    ElMessage({
      message: value,
      type: "info",
    });
  }
};

window.confirm = async function (value: string | any):boolean {
  let message;
  let title = "确认对话框";
  let confirmButtonText = "确认";
  let cancelButtonText = "取消";
  if (typeof value == "object") {
    message = value.message;
    title = value.title || title;
    confirmButtonText = value.confirmButtonText || confirmButtonText;
    cancelButtonText = value.cancelButtonText || cancelButtonText;
  } else {
    message = value;
  }
  try {
    await ElMessageBox.confirm(message, title, {
      confirmButtonText,
      cancelButtonText,
    });
    return true;
  } catch {
    return false;
  }
};
</script>

<style>
.icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}

* {
  padding: 0px;
  margin: 0px;
  list-style: none;
  text-decoration: none;
  box-sizing: border-box;
}
</style>
